/*
 * Converter.cpp
 *
 *  Created on: Dec 25, 2013
 *      Author: knuke
 */

#include "Converter.hpp"

#include <stddef.h>
#include <cstdarg>
#include <cstdio>
#include <iostream>

#include "AssimpImporter.hpp"
#include "G3DMExporter.hpp"
#include "Importer.hpp"

//#include "ConverterException.h"

using std::cout;
using std::endl;
using std::ostream;
using std::string;
using std::vector;

namespace gengine
{
  ostream* Converter::verbose_stream_ = &cout;
  bool Converter::verbose_ = false;

  Converter::Converter() :
      importer_(new AssimpImporter()), exporter_(new G3DMExporter())
  {
  }

  Converter::~Converter()
  {
  }

  void Converter::convert(std::string in_file, std::string out_file)
  {
    Model* model = importer_->importModel(in_file);
    exporter_->exportModel(model, out_file);
  }

  void Converter::verboseWriteLn(const char* format, ...)
  {
    if (Converter::verbose_)
    {
      va_list arg_list;
      va_start(arg_list, format);
      size_t buffer_size = 256;
      char* msg = new char[buffer_size];
      size_t needed_chars = vsnprintf(msg, buffer_size, format, arg_list) + 1;
      if (needed_chars > buffer_size)
      {
        delete[] msg;
        msg = new char[needed_chars];
        vsnprintf(msg, needed_chars, format, arg_list);
      }
      *Converter::verbose_stream_ << msg << endl;
    }
  }

  void Converter::setVerboseStream(std::ostream& verbose_stream)
  {
    verbose_stream_ = &verbose_stream;
  }

  void Converter::setVerbose(bool verbose)
  {
    verbose_ = verbose;
  }

} /* namespace cc_model */

